package com.peakmain.wanandroid.mymodule.animation;

import android.view.View;

/**
 * @author ：Peakmain
 * version ：1.0
 * createTime ：2018/10/17 0017 上午 11:33
 * mail : 2726449200@qq.com
 * describe ：
 */
public class PageTransformer3DGallery extends BasePageTransformer {

    private float mMaxScale = 0.5f;

    public PageTransformer3DGallery(float maxScale) {
        setMaxScale(maxScale);
    }

    @Override
    public void touch2Left(View view, float position) {
        float scaleValue = 1 - Math.abs(position) * mMaxScale;
        view.setScaleX(scaleValue);
        view.setScaleY(scaleValue);
        view.setAlpha(scaleValue);
        //设置中心点
        view.setPivotX(view.getWidth() * (1 - position - (position > 0 ? 1 : -1) * 0.75f) * mMaxScale);
        view.setElevation(position > -0.25 && position < 0.25 ? 1 : 0);
    }

    @Override
    public void touch2Right(View view, float position) {
        float scale = 0.5f;
        float scaleValue = 1 - Math.abs(position) * scale;
        view.setScaleX(scaleValue);
        view.setScaleY(scaleValue);
        view.setAlpha(scaleValue);
        view.setPivotX(view.getWidth() * (1 - position - (position > 0 ? 1 : -1) * 0.75f) * scale);
        view.setElevation(position > -0.25 && position < 0.25 ? 1 : 0);
    }

    @Override
    public void other(View view, float position) {

    }

    public void setMaxScale(float maxScale) {
        if (maxScale > 0 && maxScale <= 0.5) {
            mMaxScale = maxScale;
        }
    }
}
